package com.zzx.test.io;

import com.alibaba.fastjson.JSON;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

/**
 * @ClassName: HomeWork1
 * @Description: 练习1
 * @Author zhouzhixin
 * @Date 2021/12/2
 * @Version 1.0
 */
public class HomeWork3 {

    @Test
    public void test1() {
        String filePath1 = "C:\\Users\\lenovo\\IdeaProjects\\JavaTest\\src\\test\\java\\com\\zzx\\test\\io\\dog.properties";
        try {
            Dog dog = new Dog();
            Properties properties = new Properties();
            properties.load(new FileReader(filePath1));
            if (StringUtils.isNotBlank(properties.getProperty("name"))) {
                dog.setName(properties.getProperty("name"));
            }
            if (StringUtils.isNotBlank(properties.getProperty("age"))) {
                dog.setAge(Integer.valueOf(properties.getProperty("age")));
            }
            if (StringUtils.isNotBlank(properties.getProperty("color"))) {
                dog.setColor(properties.getProperty("color"));
            }
            System.out.println(JSON.toJSONString(dog));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Data
    public static class Dog {
        private String name;
        private Integer age;
        private String color;
    }

}
